home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / ExternalClient-Xlib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-29  |  4.0 KB  |  142 lines

  1. /* External client, raw Xlib version.
  2.    Copyright (C) 1993, 1994 Sun Microsystems, Inc.
  3.  
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8.  
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. Library General Public License for more details.
  13.  
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free
  16. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  17.  
  18. /* Synched up with: Not in FSF. */
  19.  
  20. /* Written by Ben Wing, February 1994. */
  21.  
  22. #include <X11/Xlib.h>
  23. #include <X11/Xresource.h>
  24. #include <X11/Xutil.h>
  25. #include "extw-Xlib.h"
  26.  
  27. /* this is not a perfect solution, but otherwise we have to include all
  28.    of the Xt junk */
  29.  
  30. #define XtGeometryNo 1
  31.  
  32. #if (XlibSpecificationRelease < 5)
  33. # define XPointer char *
  34. #endif
  35.  
  36. static int context_inited;
  37. static XContext focus_context;
  38.  
  39. /* does the specified window have the focus, given that the pointer just
  40.    entered (or left) the window (according to enter_p)?  This question
  41.    does not have an obvious answer in X.  (Basically, X sucks.) */
  42.  
  43. static int window_has_focus_p (Display *display, Window win, int enter_p)
  44. {
  45.   Window focuswin;
  46.   int dummy;
  47.  
  48.   XGetInputFocus(display, &focuswin, &dummy);
  49.   if (focuswin == PointerRoot)
  50.     return enter_p;
  51.   if (focuswin == win)
  52.     return True;
  53.   if (!enter_p)
  54.     return False;
  55.   do
  56.     {
  57.       Status st;
  58.       Window root_win, parent_win;
  59.       Window *child_win;
  60.       int nchild;
  61.  
  62.       st = XQueryTree(display, win, &root_win, &parent_win, &child_win,
  63.               &nchild);
  64.       if (!st)
  65.     return False;
  66.       XFree((XPointer)child_win);
  67.       if (parent_win == focuswin)
  68.     return True;
  69.       if (parent_win == root_win)
  70.     return False;
  71.       win = parent_win;
  72.     }
  73.   while (1);
  74. }
  75.  
  76.   
  77. /* External entry points when using XLib directly */
  78.  
  79. void ExternalClientInitialize (Display *display, Window win)
  80. {
  81.   extw_initialize_atoms(display);
  82.   extw_which_side = extw_client_send;
  83.   if (!context_inited)
  84.     {
  85.       focus_context = XUniqueContext();
  86.       context_inited = 1;
  87.     }
  88.   XSaveContext(display, win, focus_context, 0);
  89.   XSelectInput(display, win, EnterWindowMask | LeaveWindowMask |
  90.            FocusChangeMask);
  91. }
  92.  
  93. void ExternalClientEventHandler (Display *display, Window win, XEvent *event)
  94. {
  95.   if (win != event->xany.window)
  96.     return;
  97.   
  98.   if (event->type == ClientMessage &&
  99.       event->xclient.message_type == a_EXTW_NOTIFY &&
  100.       event->xclient.data.l[0] == extw_shell_send)
  101.     switch (event->xclient.data.l[1]) {
  102.     case extw_notify_gm:
  103.       /* for the moment, just refuse geometry requests. */
  104.       extw_send_notify_3(display, win, extw_notify_gm, XtGeometryNo, 0, 0);
  105.       break;
  106.       
  107.     case extw_notify_init:
  108.       extw_send_notify_3(display, win, extw_notify_init, EXTW_TYPE_XLIB, 0, 0);
  109.       break;
  110.       
  111.     case extw_notify_end:
  112.       XClearArea(display, win, 0, 0, 0, 0, True);
  113.       break;
  114.     }
  115.   else
  116.     {
  117.       int focus_status;
  118.       XPointer current_focus;
  119.  
  120.       if (event->type == FocusIn)
  121.     focus_status = 1;
  122.       else if (event->type == FocusOut)
  123.     focus_status = 0;
  124.       else if (event->type == EnterNotify &&
  125.            event->xcrossing.detail != NotifyInferior)
  126.     focus_status = window_has_focus_p(display, win, 1);
  127.       else if (event->type == LeaveNotify &&
  128.            event->xcrossing.detail != NotifyInferior)
  129.     focus_status = window_has_focus_p(display, win, 0);
  130.       else
  131.     return;
  132.       XFindContext(display, win, focus_context, ¤t_focus);
  133.       if (focus_status != (int) current_focus)
  134.     {
  135.       XSaveContext(display, win, focus_context, (XPointer) focus_status);
  136.       extw_send_notify_3(display, win, focus_status ?
  137.                  extw_notify_focus_in : extw_notify_focus_out,
  138.                  0, 0, 0);
  139.     }
  140.     }
  141. }
  142.